﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuanLiNhaSachBUS;

namespace QuanLiNhaSachGUI
{
    public partial class frmBaoCao : Form
    {
        public frmBaoCao()
        {
            InitializeComponent();
            dataNhap.CellClick += new DataGridViewCellEventHandler(dataNhap_CellClick);
            dataXuat.CellClick += new DataGridViewCellEventHandler(dataXuat_CellClick);
        }

        void dataXuat_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                new frmChiTietHoaDon(BaoCaoBUS.layChiTietPhieuXuat(dataXuat[0, e.RowIndex].Value.ToString())).ShowDialog();
            }
            catch (Exception ex)
            {
            }
        }

        void dataNhap_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                new frmChiTietPhieuNhap(BaoCaoBUS.layChiTietPhieuNhap(dataNhap[0, e.RowIndex].Value.ToString())).ShowDialog();
            }
            catch (Exception ex)
            {
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            dataNhap.DataSource = BaoCaoBUS.layPhieuNhap(dateTimePicker1.Value, dateTimePicker2.Value);
            dataXuat.DataSource = BaoCaoBUS.layPhieuXuat(dateTimePicker1.Value, dateTimePicker2.Value);
            txtTongTienNhap.Text = BaoCaoBUS.layTongTienNhap(dateTimePicker1.Value, dateTimePicker2.Value);
            txtTongTienXuat.Text = BaoCaoBUS.layTongTienXuat(dateTimePicker1.Value, dateTimePicker2.Value);
            dataNhap.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dataXuat.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
        }

        private void frmBaoCao_Load(object sender, EventArgs e)
        {

        }

        private void frmBaoCao_FormClosed(object sender, FormClosedEventArgs e)
        {
            frmMain.listForm.Remove(this);
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            new frmReportViewer().viewBCNhap(BaoCaoBUS.layPhieuNhap(dateTimePicker1.Value, dateTimePicker2.Value));
        }

        private void button2_Click(object sender, EventArgs e)
        {
            new frmReportViewer().viewBCBan(BaoCaoBUS.layPhieuXuat(dateTimePicker1.Value, dateTimePicker2.Value));
        }
    }
}
